package my.example.samplegridview.modal;

import java.util.Vector;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

public class product{
	
	public static final String Table = "o2s_product";
    public static final Uri    CONTENT_URI = Uri.parse("content://o2s.contentprovider.datacontentprovider/product");
    public static final String SQLCREATE = "CREATE TABLE "+Table+" ( " +
    								"'product_id' int(11) NOT NULL, " +
    								"'model' varchar(64)  , " +
    								"'sku' varchar(64)  , " +
    								"'location' varchar(128)  , " +
    								"'quantity' int(4)  DEFAULT '0', " +
    								"'stock_status_id' int(11) , " +
    								"'image' varchar(255)  DEFAULT NULL, " +
    								"'manufacturer_id' int(11) , " +
    								"'shipping' int(1)  DEFAULT '1', " +
    								"'price' decimal(15,4)  DEFAULT '0.0000', " +
    								"'tax_class_id' int(11) , " +
    								"'date_available' date , " +
    								"'weight' decimal(5,2)  DEFAULT '0.00', " +
    								"'weight_class_id' int(11)  DEFAULT '0', " +
    								"'length' decimal(5,2)  DEFAULT '0.00', " +
    								"'width' decimal(5,2)  DEFAULT '0.00', " +
    								"'height' decimal(5,2)  DEFAULT '0.00', " +
    								"'length_class_id' int(11)  DEFAULT '0', " +
    								"'status' int(1)  DEFAULT '0', " +
    								"'date_added' datetime  DEFAULT '0000-00-00 00:00:00', " +
    								"'date_modified' datetime  DEFAULT '0000-00-00 00:00:00', " +
    								"'viewed' int(5)  DEFAULT '0', " +
    								"'sort_order' int(11)  DEFAULT '0', " +
    								"'subtract' int(1)  DEFAULT '1', " +
    								"'minimum' int(11)  DEFAULT '1', " +
    								"'cost' decimal(15,4)  DEFAULT '0.0000', PRIMARY KEY (product_id) );";
	
	private String product_id;
	private String model;
	private String sku;
	private String location;
	private String quantity;
	private String stock_status_id;
	private String image;
	private String manufacturer_id;
	private String shipping;
	private String price;
	private String tax_class_id;
	private String date_available;
	private String weight;
	private String weight_class_id;
	private String length;
	private String width;
	private String height;
	private String length_class_id;
	private String status;
	private String date_added;
	private String date_modified;
	private String viewed;
	private String sort_order;
	private String subtract;
	private String minimum;
	private String cost;
	
	private String orderedQuantity;
	private String remarks;
	private productdescription prodescription;
	private Context mContext;
	private Vector<product_option> product_options;
	private String orderBy;
	
	// Preparing ... / Sent .... / Paid .....
	private String productStatus;
	
	public product(){}

	public product(Context mContext){
		this.mContext = mContext;
    	prodescription = new productdescription();
    	product_options = new Vector<product_option>();
	}
	
	public static Vector<product> SelectProducts(Context mContext){
		return SelectProducts(mContext,null,null,null,null);
	}
	
	public static Vector<product> SelectProducts(Context mContext , 
													String[] projection,
													String selection, 
													String[] selectArg,
													String sortOrder){
		Vector<product> products = new Vector<product>();
		
		Cursor c = mContext.getContentResolver().query(product.CONTENT_URI, projection, selection,selectArg, sortOrder);
		while(c.moveToNext()){
			product p = new product(mContext);
			p.setProduct_id(c.getString(0));
    		p.setModel(c.getString(1));
    		p.setSku(c.getString(2));
    		p.setLocation(c.getString(3));
    		p.setQuantity(String.valueOf(c.getDouble(4)));
    		p.setStock_status_id(String.valueOf(c.getInt(5)));
			p.setImage(c.getString(6));
			p.setManufacturer_id(String.valueOf(c.getInt(7)));
			p.setShipping(String.valueOf(c.getInt(8)));
			p.setPrice(String.valueOf(c.getDouble(9)));
			p.setManufacturer_id(String.valueOf(c.getInt(10)));
			p.setDate_available(c.getString(11));
			p.setWeight(String.valueOf(c.getDouble(12)));
			p.setWeight_class_id(String.valueOf(c.getInt(13)));
			p.setLength(String.valueOf(c.getDouble(14)));
			p.setWidth(String.valueOf(c.getDouble(15)));
			p.setHeight(String.valueOf(c.getDouble(16)));
			p.setLength_class_id(String.valueOf(c.getInt(17)));
			p.setStatus(String.valueOf(c.getInt(18)));
			p.setDate_added(c.getString(19));
			p.setDate_modified(c.getString(20));
			p.setViewed(String.valueOf(c.getInt(21)));
			p.setSort_order(String.valueOf(c.getInt(22)));
			p.setSubtract(String.valueOf(c.getInt(23)));
			p.setMinimum(String.valueOf(c.getInt(24)));
			p.setCost(String.valueOf(c.getDouble(25)));
			
			products.add(p);
		}
		c.close();
		
		return products;
	}

	public product(Context mContext , String product_id){
    	this.mContext = mContext;
    	this.product_id = product_id;
    	prodescription = new productdescription();
    	
    	String[] args = {product_id};
    	Cursor c = mContext.getContentResolver().query(product.CONTENT_URI, null, "product_id=?",args, null);
    	while(c.moveToNext()){
    		this.setProduct_id(product_id);
    		this.setModel(c.getString(1));
    		this.setSku(c.getString(2));
    		this.setLocation(c.getString(3));
    		this.setQuantity(String.valueOf(c.getDouble(4)));
    		this.setStock_status_id(String.valueOf(c.getInt(5)));
			this.setImage(c.getString(6));
			this.setManufacturer_id(String.valueOf(c.getInt(7)));
			this.setShipping(String.valueOf(c.getInt(8)));
			this.setPrice(String.valueOf(c.getDouble(9)));
			this.setManufacturer_id(String.valueOf(c.getInt(10)));
			this.setDate_available(c.getString(11));
			this.setWeight(String.valueOf(c.getDouble(12)));
			this.setWeight_class_id(String.valueOf(c.getInt(13)));
			this.setLength(String.valueOf(c.getDouble(14)));
			this.setWidth(String.valueOf(c.getDouble(15)));
			this.setHeight(String.valueOf(c.getDouble(16)));
			this.setLength_class_id(String.valueOf(c.getInt(17)));
			this.setStatus(String.valueOf(c.getInt(18)));
			this.setDate_added(c.getString(19));
			this.setDate_modified(c.getString(20));
			this.setViewed(String.valueOf(c.getInt(21)));
			this.setSort_order(String.valueOf(c.getInt(22)));
			this.setSubtract(String.valueOf(c.getInt(23)));
			this.setMinimum(String.valueOf(c.getInt(24)));
			this.setCost(String.valueOf(c.getDouble(25)));
    	}
    	c.close();
    	
    	product_options = new Vector<product_option>();
    	getProduct_options();
    }
	
	public String getProduct_id() {
		return product_id;
	}
	public void setProduct_id(String product_id) {
		this.product_id = product_id;
	}
	public String getModel() {
		return model;
	}
	public void setModel(String model) {
		this.model = model;
	}
	public String getSku() {
		return sku;
	}
	public void setSku(String sku) {
		this.sku = sku;
	}
	public String getLocation() {
		return location;
	}
	public void setLocation(String location) {
		this.location = location;
	}
	public String getQuantity() {
		return quantity;
	}
	public void setQuantity(String quantity) {
		this.quantity = quantity;
	}
	public String getStock_status_id() {
		return stock_status_id;
	}
	public void setStock_status_id(String stock_status_id) {
		this.stock_status_id = stock_status_id;
	}
	public String getImage() {
		return image;
	}
	public void setImage(String image) {
		this.image = image;
	}
	public String getManufacturer_id() {
		return manufacturer_id;
	}
	public void setManufacturer_id(String manufacturer_id) {
		this.manufacturer_id = manufacturer_id;
	}
	public String getShipping() {
		return shipping;
	}
	public void setShipping(String shipping) {
		this.shipping = shipping;
	}
	public String getPrice() {
		return price;
	}
	public void setPrice(String price) {
		this.price = price;
	}
	public String getTax_class_id() {
		return tax_class_id;
	}
	public void setTax_class_id(String tax_class_id) {
		this.tax_class_id = tax_class_id;
	}
	public String getDate_available() {
		return date_available;
	}
	public void setDate_available(String date_available) {
		this.date_available = date_available;
	}
	public String getWeight() {
		return weight;
	}
	public void setWeight(String weight) {
		this.weight = weight;
	}
	public String getWeight_class_id() {
		return weight_class_id;
	}
	public void setWeight_class_id(String weight_class_id) {
		this.weight_class_id = weight_class_id;
	}
	public String getLength() {
		return length;
	}
	public void setLength(String length) {
		this.length = length;
	}
	public String getWidth() {
		return width;
	}
	public void setWidth(String width) {
		this.width = width;
	}
	public String getHeight() {
		return height;
	}
	public void setHeight(String height) {
		this.height = height;
	}
	public String getLength_class_id() {
		return length_class_id;
	}
	public void setLength_class_id(String length_class_id) {
		this.length_class_id = length_class_id;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getDate_added() {
		return date_added;
	}
	public void setDate_added(String date_added) {
		this.date_added = date_added;
	}
	public String getDate_modified() {
		return date_modified;
	}
	public void setDate_modified(String date_modified) {
		this.date_modified = date_modified;
	}
	public String getViewed() {
		return viewed;
	}
	public void setViewed(String viewed) {
		this.viewed = viewed;
	}
	public String getSort_order() {
		return sort_order;
	}
	public void setSort_order(String sort_order) {
		this.sort_order = sort_order;
	}
	public String getSubtract() {
		return subtract;
	}
	public void setSubtract(String subtract) {
		this.subtract = subtract;
	}
	public String getMinimum() {
		return minimum;
	}
	public void setMinimum(String minimum) {
		this.minimum = minimum;
	}
	public String getCost() {
		return cost;
	}
	public void setCost(String cost) {
		this.cost = cost;
	}
	public String getOrderedQuantity() {
		return orderedQuantity;
	}
	public void setOrderedQuantity(String orderedQuantity) {
		this.orderedQuantity = orderedQuantity;
	}
	public String getRemarks() {
		return remarks;
	}
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}
	public String getOrderBy() {
		return orderBy;
	}
	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}
	
	public String getProductStatus() {
		return productStatus;
	}

	public void setProductStatus(String productStatus) {
		this.productStatus = productStatus;
	}

	public productdescription getProdescription() {
		String[] arg = {this.product_id};
		Cursor c = mContext.getContentResolver().query(productdescription.CONTENT_URI, null, "product_id=?", arg, null);
		while(c.moveToNext()){
			prodescription.setProduct_id(this.product_id);
			prodescription.setLanguage_id(String.valueOf(c.getInt(1)));
			prodescription.setName(c.getString(2));
			prodescription.setMeta_keywords(c.getString(3));
			prodescription.setMeta_description(c.getString(4));
			prodescription.setDescription(c.getString(5));
		}
		c.close();
		return prodescription;
	}
	
	public Vector<product_option> getProduct_options() {
		
		String[] arg = {product_id};
		Cursor c = mContext.getContentResolver().query(product_option.CONTENT_URI, null, "product_id=?", arg, null);
		product_option po;
		while(c.moveToNext()){
			po = new product_option(mContext);
			po.setProduct_option_id(String.valueOf(c.getInt(0)));
			po.setProduct_id(product_id);
			po.setSort_order(String.valueOf(c.getInt(2)));
			po.getProduct_option_values();
			product_options.add(po);
		}
		c.close();
		
		return product_options;
	}
	
	public Vector<product_option> getProduct_options(boolean in) {
		return product_options;
	}
}